package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Contant;

/**
 * 
 * @author 
 *
 */
@DAO
public interface ContantDAO{
	
	@SQL("SELECT id,title,category,abstractInfor,carouselImage,content,author,releaseState,date_format(releaseAT,'%Y-%m-%d %H:%i:%s') as releaseAT,orderNo,source,qrCode,stickAT,deleteFlag,createUser,date_format(createAT,'%Y-%m-%d %H:%i:%s') as createAT,updateUser,date_format(updateAT,'%Y-%m-%d %H:%i:%s') as updateAT FROM Contant WHERE deleteFlag=1 #if(:t.title!=''){and title like '%##(:t.title)%' } #if(:t.category!=''){AND category = :t.category } ORDER BY stickAT DESC,updateAT DESC LIMIT :t.start,:t.length ")
    List<Contant> query(@SQLParam("t") Contant Contant);
	
	@SQL("SELECT count(id) FROM Contant WHERE deleteFlag=1  #if(:t.title!=''){and title like '%##(:t.title)%' }  #if(:t.category!=''){AND category = :t.category }")
    int querysize(@SQLParam("t") Contant Contant);
    
    @SQL("select * from Contant where id=:1")
    Contant queryById(int id);
    
    @SQL("INSERT INTO Contant (title,category,abstractInfor,carouselImage,content,author,releaseState,releaseAT,orderNo,source,qrCode,deleteFlag,createUser,createAT,updateUser,updateAT) VALUES (:t.title,:t.category,:t.abstractInfor,:t.carouselImage,:t.content,:t.author,:t.releaseState,:t.releaseAT,:t.orderNo,:t.source,:t.qrCode,:t.deleteFlag,:t.createUser,now(),:t.updateUser,now())")
    void create(@SQLParam("t") Contant Contant);
    
    @SQL("INSERT INTO Contant (title,category,abstractInfor,carouselImage,content,author,releaseState,releaseAT,orderNo,source,qrCode,deleteFlag,createUser,createAT,updateUser,updateAT) select title,:2,abstractInfor,carouselImage,content,author,releaseState,now(),orderNo,source,qrCode,deleteFlag,createUser,now(),updateUser,now() from Contant where id=:1 ")
    void createCoptById(int id,int category);
	
	@SQL("UPDATE Contant SET title=:t.title,category=:t.category,abstractInfor=:t.abstractInfor,carouselImage=:t.carouselImage,content=:t.content,author=:t.author,releaseState=:t.releaseState,releaseAT=now(),orderNo=:t.orderNo,source=:t.source,qrCode=:t.qrCode,updateUser=:t.updateUser,updateAT=now() WHERE id=:t.id")
    void update(@SQLParam("t") Contant Contant);
	
	@SQL("UPDATE Contant SET stickAT=now(),updateAT=now() WHERE id=:1")
    void updateByStickTime(int id);
	
	@SQL("UPDATE Contant SET stickAT=null,updateAT=now() WHERE id=:1")
    void updateByStickTimeIsNull(int id);
	
    @SQL("UPDATE Contant SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);

    @SQL("INSERT INTO Contant (title,category,abstractInfor,carouselImage,content,author,releaseState,releaseAT,orderNo,source,qrCode,deleteFlag,createUser,createAT,updateUser,updateAT) select title,:2,abstractInfor,carouselImage,content,author,releaseState,now(),orderNo,:3,qrCode,deleteFlag,createUser,now(),updateUser,now() from Industry where id=:1 ")
	void copyFromIndustry(int id, int category, int source);
}